﻿using Microsoft.AspNetCore.Http;
using Models.Common;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using Microsoft.EntityFrameworkCore;
using System.Data.SqlTypes;
using UtilsORM;
using UtilsORM.MySqlData;
using UtilsCache;
using Newtonsoft.Json.Linq;
////using System.Web.Script.Serialization;

namespace GatewayServerService.Data
{
    public class DBIotWarnLog
    {

        /// <summary>
        /// 新增预警日志
        /// </summary>
        /// <param name="dguid"></param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="name"></param>
        /// <param name="remark"></param>
        public void addWarnLogSync(string dguid, string key, string value, string name, string remark)
        {
            Task.Run(() =>
            {
                try
                {
                    int warn = 0;//不报警
                    if (value == "yes")
                    {
                        warn = 1;//报警
                    }

                    //判断产品是否自动运行
                    EFYihongIotContext ef = new EFYihongIotContext();
                    iot_warn_log log = new iot_warn_log();
                    log.wl_guid = Guid.NewGuid().ToString();
                    log.wl_warn_status = warn;
                    log.wl_add_time = DateTime.Now;
                    log.wl_key = key;
                    log.wl_value = value;
                    log.wl_d_guid = dguid;
                    log.wl_remark = remark;
                    log.wl_key_name = name;
                    ef.iot_warn_log.Add(log);
                    ef.SaveChanges();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            });
        }

    }
}
